package com.obor.quartz.job.controller;

import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.zn.mvcbase.response.status.Success;

import com.google.common.base.Strings;
import com.obor.quartz.job.JobInfo;
import com.obor.quartz.job.service.JobService;

/**
* 
* @Company OBOR
* @Author 周楠
* @Description
* 2019年3月1日
*
*/
@RestController
@RequestMapping("job")
public class JobController {
	
	@Autowired
	private JobService jobService;
	
	
	@RequestMapping("start")
	public String schedulerStart() throws SchedulerException{
		
		jobService.serverStart();
		
		return Success.MAINSUCCESS;
		
	}
	
	@RequestMapping("addTest")
	public String addJobTest(JobInfo job) throws SchedulerException{
		
		
		job.setBeanClass("com.obor.quartz.job.biz.HelloJob");
		
		if(Strings.isNullOrEmpty(job.getName())) job.setName("Job-test1");
		if(Strings.isNullOrEmpty(job.getKey())) job.setKey("test1");
		if(Strings.isNullOrEmpty(job.getGroup())) job.setGroup("g1");
		if(Strings.isNullOrEmpty(job.getCronExpression())) job.setCronExpression("5/30 * * * * ? ");
		
		jobService.add(job);
		
		return Success.MAINSUCCESS;
		
	}
	
	
	@RequestMapping("add")
	public String addJob(JobInfo job) throws SchedulerException{
		
		jobService.add(job);
		
		return Success.MAINSUCCESS;
		
	}
	
	
	@RequestMapping("delete")
	public String addJobTest(String jobKey,String group) throws SchedulerException{
		
		jobService.del(jobKey, group);
		
		return Success.MAINSUCCESS;
		
	}
	
	
	@RequestMapping("pause")
	public String pauseJob(String jobKey,String group) throws SchedulerException{
		
		jobService.pause(jobKey, group);
		
		
		return Success.MAINSUCCESS;
		
	}
	
	@RequestMapping("resume")
	public String resume(String jobKey,String group) throws SchedulerException{
		
	
		jobService.resume(jobKey, group);
		
		
		return Success.MAINSUCCESS;
		
	}
	
	
	@RequestMapping("testctx")
	public String testctx(String jobKey) throws SchedulerException{
		
		
		return Success.MAINSUCCESS;
		
	}
	
	@RequestMapping("mongo")
	public Object mongo() throws SchedulerException{
		
	//  List<Map> list=	mongoService.queryTest();
		
		
		return null;
		
	}
	
	
	
	
}
